using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ByHand.Model;
using ByHand.Data;
using ByHand.Services.Interfaces;
using ByHand.Data.Interfaces;
using ByHand.Services.Code;
using System.Configuration;

namespace ByHand.Services.Implements
{
    public class UtilityService
    {
        public static ByHandDB GetData()
        {
            return new ByHandDB(ConfigurationManager.ConnectionStrings["ByHandDB"].ConnectionString);
        }

        public static List<City> GetAllCities()
        {
            using (var db = GetData())
            {
                return (from c in db.Cities select c).ToList();
            }
        }
        public static List<District> GetAllDistrict()
        {
            using (var db = GetData())
            {
                return (from d in db.Districts select d).ToList();
            }
        }
        public static void UpdateProduct(int guuID, int status)
        {
            using (var db = GetData())
            {
                var p = (from d in db.Products
                         where d.GuuID == guuID
                         select d).FirstOrDefault();
                if (p != null && p.GuuStatus != status)
                {
                    p.GuuStatus = status;
                    db.SaveChanges();
                }
            }
        }
        public static List<int> GetAllMerchantID()
        {
            using (var db = GetData())
            {
                return (from d in db.Providers
                        where !d.IsDeleted && d.MerchantID != null && d.MerchantID != 0
                        select (int)d.MerchantID).ToList();
            }
        }
    }
}
